<?php
namespace Tongcheng\Controller;
use Think\Controller;
class CouponController extends CommonController {
    public function index(){
    	$model = M("Coupon");
    	$map['tp_coupon.wid'] = session('wid');
        $map['tp_coupon.status'] = 1;
    	$list = $model->field("tp_coupon.*,s.name")->join("tp_shop s on s.shop_id = tp_coupon.shop_id")->where($map)->select();
        foreach($list as $k=>$v){
            $tui = M("tui")->where(['wid'=>session('wid'),'aid'=>$v['id'],"type"=>'coupon'])->find();
            if(!$tui || !$tui['status']){
                $list[$k]['is_tui'] = 0;
            }else{
                $list[$k]['is_tui'] = 1;
            }
        }
        $this->assign("list",$list);
        $this->display();
    }
    public function tui(){
        $r = tui("coupon",I('id'),session('wid'),$_POST['status']);
        if($r){
            $this->success("操作成功！");
        }else{
            $this->error("网络忙，请稍后再试！");
        }
    }

    public function add(){
    	$model = M("InfoCate");
    	$map['wid'] = session('wid');
    }

    public function edit(){
    	$model = M("InfoCate");
    	$map['wid'] = session('wid');
    }

    public function del(){
    	$model = M("InfoCate");
    	$map['wid'] = session('wid');
    }
}